package com.gitee.wsl.func.filter.bloomfilter

import com.gitee.wsl.func.filter.bloomfilter.api.BitMapExtractor
import com.gitee.wsl.func.filter.bloomfilter.bean.Shape
import com.gitee.wsl.func.predicate.Predicate
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue


/**
 * Tests for the [SimpleBloomFilter].
 */
class SimpleBloomFilterTest : AbstractBloomFilterTest<SimpleBloomFilter>() {
    override fun createEmptyFilter(shape: Shape): SimpleBloomFilter {
        return SimpleBloomFilter(shape)
    }

    @Test
    fun testMergeShortBitMapExtractor() {
        val filter: SimpleBloomFilter = createEmptyFilter(testShape)
        // create a bitMapExtractor that returns too few values
        // shape expects 2 longs we are sending 1.
        val bitMapExtractor = BitMapExtractor { p: Predicate<Long> -> p.test(2L) }
        assertTrue(filter.merge(bitMapExtractor))
        assertEquals(1, filter.cardinality())
    }
}
